/*
Package middlewares
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2024/3/27 14:44
@File     : guest_jwt.go
@Project  : gohub
@Desc     :
*/
package middlewares

import (
	"github.com/gin-gonic/gin"
	"gohub/pkg/jwt"
	"gohub/pkg/response"
)

func GuestJWT() gin.HandlerFunc {
	return func(c *gin.Context) {
		if len(c.GetHeader("Authorization")) > 0 {
			//解析token成功，说明登录成功
			_, err := jwt.NewJWT().ParserToken(c)
			if err == nil {
				response.Unauthorized(c, "请使用游客身份访问")
				c.Abort()
				return
			}
		}

		c.Next()
	}
}
